import https from 'wechat-http'

// 接口基地址
// 生产
https.baseURL = "https://j.kaletcg.com/lzmtest"
// 开发
// https.baseURL = "http://192.168.0.38:8081";

// 请求拦截
https.intercept.request = options => {
	const defaultHeader = {}
	defaultHeader['Content-Type'] = options.method == 'GET' ? "application/x-www-form-urlencoded" : "application/json"
	defaultHeader['api-access-token']=uni.getStorageSync("token")
	options.header = {
		...defaultHeader,
		...options.header
	}
	return options
}

// 响应拦截 
https.intercept.response = res => {
	if (res.data.code !== 200) {
		console.log(123,'res.data.code !== 200');
		uni.showToast({
			title: res.data.message,
			icon: 'none'
		});
		if(res.data.code===555){
			uni.removeStorageSync("token");
			uni.showModal({
				content: "请登录",
				success: res=> {
					if (res.confirm) {
						uni.navigateTo({
							url: "/pages/login/login",
						});
					} else if (res.cancel) {
						uni.navigateBack({});
					}
				},
			});
		}
		return
		}
	return res.data.data
}

export default https